﻿using IntelligentAgriculture.Contracts.Interface;
using IntelligentAgriculture.WebAPI.Application.Command.RoleCommand;
using MediatR;

namespace IntelligentAgriculture.WebAPI.Application.CommandHandler.RoleCommandHandler
{
    public class AddRoleCommandHandler : IRequestHandler<AddRoleCommand, Results<int>>
    {
        private readonly IRoleService _roleService;

        public AddRoleCommandHandler(IRoleService roleService)
        {
            _roleService = roleService;
        }
        /// <summary>
        /// 添加角色
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task<Results<int>> Handle(AddRoleCommand request, CancellationToken cancellationToken)
        {
            int n = await _roleService.AddRole(request.Input);
            return Results<int>.DataResult(n);
        }
    }
}
